/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/* nixonFTP
 * FTP client version 0.1
 * Copyright (C) 2010 NIXON Development Corporation.
 * All rights reserved.
 * http://members.shaw.ca/nixon.com
*/

package nixonftp.ui;

import java.awt.Color;
import nixonftp.*;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import javax.accessibility.AccessibleContext;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.border.Border;
import javax.swing.border.MatteBorder;


public class NXToolbar extends JToolBar {
	public JButton btnConnect;
	public JButton btnListing;
	public JButton btnListingLocal;
	public JButton btnFilters;
	public final JButton btnMenu;
	private static final Insets margins =
    new Insets(5, 5, 5, 5);
	public final JToggleButton btnLocal;
	public final JToggleButton btnQueue;

	class marginButton extends JButton {
		private final Insets buttonMargins =
			new Insets(6,10,6,10);
		public marginButton(String name) {
			super(name);
			this.setOpaque(false);
			this.setBorder(BorderFactory.createEmptyBorder(6,10,6,10));
			setMargin(buttonMargins);
		}
	}

	private void setAccessible(JComponent c, String name, String desc, boolean toolTip) {
		AccessibleContext ac = c.getAccessibleContext();
		ac.setAccessibleName(name);
		ac.setAccessibleDescription(desc);
		if (toolTip) c.setToolTipText(desc);
	}

	public NXToolbar(ActionListener al) {
		super("Toolbar");
		this.setFloatable(false);
		setMargin(margins);

		btnConnect = new marginButton("");
		setAccessible(btnConnect, "Connect", "Connect to server", true);
		btnConnect.setIcon(NXIcon.connect);
		btnConnect.setVisible(true);

		btnListing = new marginButton("");
		setAccessible(btnListing, "Columns/Detail (Remote)", "Change remote view", true);
		btnListing.setIcon(NXIcon.detail);
		btnListing.setVisible(false);

		btnFilters = new marginButton("");
		setAccessible(btnFilters, "Filters", "Show filters dialog", true);
		btnFilters.setIcon(NXIcon.filters);
		btnFilters.setVisible(false);

		btnLocal = new JToggleButton("Local");
		setAccessible(btnLocal, "Local", "Show local pane", true);
		btnLocal.setMargin(margins);

		btnQueue = new JToggleButton("Sidebar");
		setAccessible(btnQueue, "Local", "Show Sidebar", true);
		btnQueue.setMargin(margins);

		btnMenu = new marginButton("");
		btnMenu.setIcon(NXIcon.icon);
		setAccessible(btnMenu, "Menu", "Show menu", true);
		btnMenu.setMargin(margins);
		//btnFilters.setIcon(NXIcon.filters);

		btnConnect.addActionListener(al);
		btnListing.addActionListener(al);
		//btnListingLocal.addActionListener(al);
		btnFilters.addActionListener(al);
		btnLocal.addActionListener(al);
		btnQueue.addActionListener(al);
		btnMenu.addActionListener(al);

		add(btnMenu);
		add(btnConnect);
		add(btnListing);
		//add(btnListingLocal);
		//add(btnLocal);
		//add(btnQueue);
		add(btnFilters);
		this.setBackground(Color.WHITE);
		this.setBorder(new MatteBorder(0, 1, 0, 0, Color.GRAY));
		this.setOpaque(true);
	}
}
